﻿using System.Linq.Expressions;
using MicroBlog.Infrastructure;
using MicroBlog.Models;
using MicroBlog.ViewModels;

namespace MicroBlog.Services
{
    /// <summary>
    /// 博客管理接口
    /// </summary>
    public interface IBlogManager
    {
        #region 博客管理
        /// <summary>
        /// 写博客
        /// </summary>
        /// <param name="blog"></param>
        /// <returns></returns>
        Task<ContextResult> WriteAsync(Blog blog);
        /// <summary>
        /// 更新博客
        /// </summary>
        /// <param name="blog"></param>
        /// <returns></returns>
        Task<ContextResult> UpdateAsync(Blog blog);
        /// <summary>
        /// 删除博客
        /// </summary>
        /// <param name="blogId"></param>
        /// <returns></returns>
        Task<ContextResult> RemoveAsync(int blogId);
        /// <summary>
        /// 查询博客的详细信息
        /// </summary>
        /// <param name="blogId"></param>
        /// <returns></returns>
        Task<BlogViewModel> FindAsync(int blogId);
        /// <summary>
        /// 查询博客的详细信息
        /// </summary>
        /// <param name="blogId"></param>
        /// <returns></returns>
        Task<Blog> FirstOrDefaultAsync(int blogId);
        /// <summary>
        /// 根据关键字查询博客
        /// </summary>
        /// <param name="predicate"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        Task<IPagedList<Blog>> SearchAsync(Expression<Func<Blog, bool>> predicate, int pageIndex = 0, int pageSize = int.MaxValue);
        /// <summary>
        /// 根据标签查询博客
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        Task<IPagedList<Blog>> SearchByTagAsync(string tag, int pageIndex = 0, int pageSize = int.MaxValue);
        #endregion

        #region 标签管理
        /// <summary>
        /// 创建一个标签
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        Task<ContextResult> CreateTagAsync(Tag tag);
        /// <summary>
        /// 更新标签，更新时会更新所有同名的标签
        /// </summary>
        /// <param name="originTag">原始名称</param>
        /// <param name="newTag">更改后的名称</param>
        /// <returns></returns>
        Task<ContextResult> UpdateTagAsync(string originTag, string newTag);
        /// <summary>
        /// 删除标签
        /// </summary>
        /// <param name="tagName"></param>
        /// <returns></returns>
        Task<ContextResult> RemoveTagAsync(string tagName);
        /// <summary>
        /// 获取所有标签
        /// </summary>
        /// <returns></returns>
        Task<IList<TagViewModel>> GetTagsAsync();
        /// <summary>
        /// 统计标签的使用情况
        /// </summary>
        /// <returns></returns>
        Task<IList<TagViewModel>> TagStatisticsAsync();
        #endregion
    }
}
